<?php
include_once(APPPATH."libraries/AdminController.php");
class auth extends AdminController {

	function __construct()  
	{
		parent::__construct(); 		
		$this->load->model('mdl_auth','A');	
		
	}
	
	function index()  
	{
		$data = array(
			'message'=>''
		);
		
		if(isset($_POST['login'])){
			$u = dbClean($_POST['username']);
			$p = md5(dbClean($_POST['password']));
			if( $u == '' || $p == '' ){
				$data['message']	= 'Login Gagal...';	
			}else{
				$d = $this->A->cekLogin($u,$p);
				if($d['count'] > 0){
					$emp = $this->A->get_info_employee($d['data']->user_id);
					// set session......
					$this->jCfg['is_login'] = 1;
					$this->jCfg['user']['id'] 		= $d['data']->user_id;
					$this->jCfg['user']['name']		= $d['data']->user_name;
					$this->jCfg['user']['asuransi']	= $d['data']->user_asuransi;
					$this->jCfg['user']['cabang']	= $d['data']->user_cabang;
					$this->jCfg['user']['fullname'] = $emp['fullname'];
					$this->jCfg['user']['foto']		= $emp['foto'];
					$this->jCfg['user']['emp_id'] 	= $emp['employee_id'];
					$this->jCfg['menu'] 			= '';
					$this->jCfg['user']['level'] 	= getGroup($d['data']->user_id);
					$this->jCfg['mod_design']		= getGroup($d['data']->user_id,true);
					
					$_SESSION[cfg('session_filemanager')]=true;
					
					if(trim($d['data']->time_update)=='' || trim($d['data']->user_update)==''){
						$this->jCfg['complete_data']= 'no';
					}
					$this->_releaseSession();
					
					$this->db->query("
						update macs_user set user_logindate = '".date("Y-m-d H:i:s")."' where user_id='".$d['data']->user_id."'
					");
					
					redirect(modUri().'meme/me');
				}else{
					$data['message']	= 'Username atau password salah';
				}
			}		
		}	
		$this->_v('login',$data,FALSE);
	}
	
	function out(){
		$this->jCfg['user']['id'] 		= '';
		$this->jCfg['user']['fullname'] = 'Guest';
		$this->jCfg['user']['name'] 	= 'guest';
		$this->jCfg['user']['level'] 	='';
		$this->jCfg['user']['foto'] 	='';
		$this->jCfg['user']['asuransi'] ='';
		$this->jCfg['complete_data']	= 'yes';
		$this->jCfg['user']['access'] 	= array();
		$this->jCfg['menu'] 			= array();
		$this->jCfg['is_login'] 		= 0;
		$this->jCfg['mod_design'] 		= '';
		$this->_releaseSession();
		$_SESSION[cfg('session_filemanager')]=false;
		redirect(modUri());
	}
	
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */